package org.junv;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@WebServlet("/UserList")
public class UserList extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
  
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
         

		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();
		
		String sql="select username,password from userInfo order by id";
		
		
		
		ResultSet rs=null;
		DBBean myBean = new DBBean();
		myBean.init();
		rs=myBean.executeQuery(sql);
		
		try {
			if(rs.next()){
				out.println("<table  border='1'>");
				out.println("<tr><th>用户名</th><th>密码</th><th>删除</th></tr>");
				while(rs.next()){
					out.println("<tr><td>"+rs.getString("username")+"</td><td>"+rs.getString("password")+
						
						"</td><td><a href='DelUser?username="+rs.getString("username")+"'>删除</a>"+"</td></tr>");
					
					
				}
				out.println("</table>");
			}else{
				out.print("没有可以显示的内容");
				return;
			}
		} catch (SQLException e) {
			
			System.out.println("Result这里出了问题。。。。");
			e.printStackTrace();
			myBean.colse();
		}
		myBean.colse();	
	}


}
